package com.crl.map.view.diy
{
	import com.crl.map.model.MapModel;
	import com.crl.map.model.TileSystem;
	import com.crl.map.utils.astar.INodeGenerater;
	import com.crl.map.utils.astar.Node;
	
	import flash.display.Graphics;

	public class NodeGenerator implements INodeGenerater
	{
		private var model:MapModel;
		
		private var nodes:Vector.<Node>;
		
		protected var tw:int;
		protected var th:int;
		public function NodeGenerator(model:MapModel)
		{
			this.model=model;
			
			tw=model.col;
			th=model.row;
			
			nodes=new Vector.<Node>();
			for(var i:int=0;i<th;i++){
				for(var j:int=0;j<tw;j++){
					var node:Node=new Node();
					node.x=i;
					node.y=j;
					nodes[i*tw+j]=node;
				}
			}
			
		}
		
		public function getNode(x:int,y:int):Node{
			return nodes[y*tw+x];
		}
		
		public function getTW():int{
			return model.col;
		}
		
		public function getTH():int{
			return model.row;
		}
		
		
		public function drawGrid(g:Graphics):void{
			g.clear();
			g.beginFill(0xff0000);
			g.lineStyle(0);
			
			
			var row:int=model.row;
			var col:int=model.col;
			
			var w:int=model.col*model.tw;
			var h:int=model.row*model.th;
			
			var iw:int=model.tw;
			var ih:int=model.th;
			
			g.drawRect(0,0,w,h);
			
			for(var i:int = 1; i < row; i ++){
				g.moveTo(iw * i,0);
				g.lineTo(iw * i,w);
				
				g.moveTo(0,ih* i);
				g.lineTo(h,ih * i);
			}
			
			
			g.endFill();
		}
		
		public function drawTrigger(g:Graphics):void{
			var w:int=model.getWidth();
			var h:int=model.getHeight();
			g.clear();
			g.beginFill(0,1);
			g.drawRect(-100,-100,w+200,h+200);
			g.endFill();
		}
	}
}